package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.Rig;
import com.ruoyi.service.IRigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 作业装配Controller
 * 
 * @author ruoyi
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/rig/rig")
public class RigController extends BaseController
{
    @Autowired
    private IRigService rigService;

    /**
     * 查询作业装配列表
     */
    @PreAuthorize("@ss.hasPermi('rig:rig:list')")
    @GetMapping("/list")
    public TableDataInfo list(Rig rig)
    {
        startPage();
        List<Rig> list = rigService.selectRigList(rig);
        return getDataTable(list);
    }

    /**
     * 导出作业装配列表
     */
    @PreAuthorize("@ss.hasPermi('rig:rig:export')")
    @Log(title = "作业装配", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Rig rig)
    {
        List<Rig> list = rigService.selectRigList(rig);
        ExcelUtil<Rig> util = new ExcelUtil<Rig>(Rig.class);
        util.exportExcel(response, list, "作业装配数据");
    }

    /**
     * 获取作业装配详细信息
     */
    @PreAuthorize("@ss.hasPermi('rig:rig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(rigService.selectRigById(id));
    }

    /**
     * 新增作业装配
     */
    @PreAuthorize("@ss.hasPermi('rig:rig:add')")
    @Log(title = "作业装配", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Rig rig)
    {
        return toAjax(rigService.insertRig(rig));
    }

    /**
     * 修改作业装配
     */
    @PreAuthorize("@ss.hasPermi('rig:rig:edit')")
    @Log(title = "作业装配", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Rig rig)
    {
        return toAjax(rigService.updateRig(rig));
    }

    /**
     * 删除作业装配
     */
    @PreAuthorize("@ss.hasPermi('rig:rig:remove')")
    @Log(title = "作业装配", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(rigService.deleteRigByIds(ids));
    }
}
